package com.inspur.edp.common.expr.visitor.construct;

import com.inspur.edp.common.expr.ast.CompileUnitParser;
import com.inspur.edp.common.expr.parser.TypeAstParser;
import com.inspur.edp.common.expr.visitor.JavaVisitor;
import com.inspur.edp.common.expr.visitor.VisitResult;
import com.inspur.edp.common.type.Type;
import com.inspur.edp.common.type.TypeRefer;

/**
 * @author lizhaorui
 * @description TODO
 * @date 2024/7/17 11:46
 */
public class JavaConstructManager {

    public static VisitResult visit(JavaVisitor javaVisitor, CompileUnitParser.TypeContext typeContext, String parameters) {
        TypeRefer typeRefer = TypeAstParser.getTypeRefer(typeContext, javaVisitor);
        return visit(javaVisitor,typeRefer, parameters);
    }

    public static VisitResult visit( JavaVisitor javaVisitor, TypeRefer typeRefer, String parameters) {
        Type type = javaVisitor.getType(typeRefer);
        String kind = type.getConstructorKind();
        if (kind == null) {
            kind = JavaDefaultConstructVisitor.MODE;
        }
        return JavaConstructFactory.getSpi(kind).visit(typeRefer, type, parameters);
    }

}
